package com.guandata.cdc.model.db_type.postgres;

import lombok.Getter;

import java.util.Arrays;

@Getter
public enum PostgresSourceMode {
    DEFAULT("default"),

    /**
     * <pre>
     * Incremental snapshot is a new mechanism to read snapshot of a table.
     * Compared to the old snapshot mechanism, the incremental snapshot has many advantages, including:
     * (1) source can be parallel during snapshot reading,
     * (2) source can perform checkpoints in the chunk granularity during snapshot reading,
     * (3) source doesn't need to acquire global read lock (FLUSH TABLES WITH READ LOCK) before snapshot reading.
     * Please see Incremental Snapshot Readingsection for more detailed information.
     * </pre>
     */
    INCREMENTAL("incremental");

    private final String code;

    PostgresSourceMode(String code) {
        this.code = code;
    }

    public static PostgresSourceMode fromCode(String mode) {
        if(mode == null) return DEFAULT;
        return Arrays.stream(values())
                .filter(x -> x.code.equalsIgnoreCase(mode))
                .findFirst()
                .orElse(DEFAULT);
    }
}
